#author: Piotr Falandysz

import unittest
from graph import Graph
from pqueue import PQueue
from dijkstra import *

class TestGraph(unittest.TestCase):
	def setUp(self):
		self.graph = Graph()
		self.graph.load_from_file("dane.txt")
		self.pqueue = PQueue()
		
	def test_pqueue_empty(self):
		"""Test kolejki priorytetowej - is_empty."""
		self.assertTrue(self.pqueue.is_empty())	
		self.pqueue.insert(("First", 2))
		self.assertFalse(self.pqueue.is_empty())
		
	def test_pqueue_insert_remove(self):
		"""Test kolejki priorytetowej - insert and remove."""
		self.pqueue.insert(("First", 20))
		self.assertEqual(self.pqueue.remove(), ("First", 20))
		
		self.pqueue.insert(("First", 20))
		self.pqueue.insert(("Second", 19))
		self.assertEqual(self.pqueue.remove(), ("Second", 19))
		self.assertEqual(self.pqueue.remove(), ("First", 20))
	
	def test_graph_dijkstra_distance(self):
		"""Test grafu - Dijkstra distance."""
		distance, predecessor = Dijkstra(self.graph.graph, "Krakow", "Szczecin")
		self.assertEqual(distance, 676)
		
	def test_graph_dijkstra_path(self):
		"""Test grafu - Dijkstra path."""
		distance, predecessor = Dijkstra(self.graph.graph,"Krakow", "Szczecin")
		self.assertEqual(getPath(predecessor, "Szczecin"), "Krakow -> Katowice -> Opole -> Wroclaw -> Zielona Gora -> Szczecin")
		
	def tearDown(self):
		"""Koncowe czynnosci czyszczace."""
		
		
if __name__ == '__main__':
	unittest.main()	